import { getToken, removeToken, setToken } from '@/utils/token'

export default {
  namespaced: true,
  state () {
    return {
      userInfo: '',
      token: getToken() || ''
    }
  },
  mutations: {
    setToken (state, val) {
      state.token = val
      setToken(val)
    },
    setUserInfo (state, val) {
      state.userInfo = val
    },
    logout(state) {
      state.userInfo = ''
      state.token = ''
      removeToken()
    }
  },
  actions: {
    SET_TOKEN (ctx, val) {
      ctx.commit('setToken', val)
    },
    SET_USERINFO (ctx, val) {
      ctx.commit('setUserInfo', val)
    },
    SET_LOGOUT(ctx) {
      ctx.commit('logout')
    }
  }
}
